package edu.shzu.manage.dao;

import edu.shzu.manage.entity.Menu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MenuDao {
    /**
     * 根据ID 查询菜单
     * @param menuId
     * @return
     */
    @Select("select * from menu where menuId = #{menuId}")
    Menu getMenuById(Integer menuId);

    /**
     * 查询所有菜单权限
     * @return
     */
    @Select("select * from menu")
    List<Menu> getAllMenu();

    @Select("select * from menu where menuName like concat('%',#{str},'%')")
    List<Menu> queryMenu(String str);

    @Insert("insert into menu(pId,menuName,menuUrl,authorize,menuType,menuLogo,sort) values(#{pId},#{menuName},#{menuUrl},#{authorize},#{menuType},#{menuLogo},#{sort})")
    int insertMenu(Menu menu);

    @Update("update menu set pId=#{pId},menuName=#{menuName},menuUrl=#{menuUrl},authorize=#{authorize},menuType=#{menuType},menuLogo=#{menuLogo},sort=#{sort} where menuId=#{menuId}")
    int updateMenu(Menu menu);

    @Delete("delete from menu where menuId=#{menuId}")
    int deleteMenu(Integer menuId);

    /**
     * 根据父ID 查询
     * @param parentId
     * @return
     */
    @Select("select * from menu where pId=#{parentId}")
    List<Menu> findByParentId(Integer parentId);
}
